package com.gzhryc.shared_device.bxscn.code.dao.db;

import com.gzhryc.common.DateTools;
import com.gzhryc.common.NumberTools;
import com.gzhryc.common.StringTools;
import com.gzhryc.jdbc.annotaion.Column;
import com.gzhryc.jdbc.annotaion.DateBranchTable;
import com.gzhryc.jdbc.annotaion.Id;
import com.gzhryc.jdbc.annotaion.Table;
import com.gzhryc.jdbc.enums.DateBranchTableType;
import com.gzhryc.shared_device.base.models.IDeviceOrder;
import com.gzhryc.shared_device.base.enums.EPayType;
import com.gzhryc.shared_device.bxscn.code.dao.enums.BXSCNOrderEnum;
import com.gzhryc.shared_device.bxscn.code.dao.enums.EBXSCNCostMode;

import java.io.Serializable;
import java.util.Date;

/**
 * 共享充电宝租借订单
 * @version 2022-09-09
 */
@DateBranchTable(type= DateBranchTableType.year)
@Table(name="bxscn_order")
public class BXSCNOrder implements IDeviceOrder, Serializable {

    private static final long serialVersionUID = 1L;

	@Id(auto = false)
    @Column(name = "trade_no")
    protected String tradeNo;

    @Column(name = "lease_device_sn", notNull = true, note = "租借充电柜设备序列号")
    protected String leaseDeviceSn;

    @Column(name = "lease_device_type_id", notNull = true,note = "设备类型ID")
    protected String leaseDeviceTypeId;

    @Column(name = "lease_device_type_name", notNull = true,note = "设备类型名称")
    protected String leaseDeviceTypeName;

    @Column(name = "lease_iot_id", notNull = true,note = "IOT节点ID")
    protected Long leaseIotId;

    @Column(name = "lease_slot_num",note = "租借时弹出卡槽位置")
    protected Integer leaseSlotNum;

    @Column(name = "lease_power", note = "租借时电量")
    protected Double leasePower;

    @Column(name = "lease_error_state", notNull = true,defVal = "0", note = "租借错误状态")
    protected Integer leaseErrorState;

    @Column(name = "lease_bind_note",note = "设备绑定信息")
    protected String leaseBindNote;

    @Column(name = "lease_place_id", notNull = true, note = "网点ID")
    protected Long leasePlaceId;

    @Column(name = "lease_place_name", note = "网点名称")
    protected String leasePlaceName;

    @Column(name ="lease_province",note = "省")
    protected String leaseProvince;

    @Column(name ="lease_city",note = "市")
    protected String leaseCity;

    @Column(name = "lease_city_area",note = "城区")
    protected String leaseCityArea;

    @Column(name="lease_address",length = 64, note = "网点地址")
    protected String leaseAddress;

    @Column(name="lease_longitude",length = 10, decimalLen = 6, note = "经度")
    protected Double leaseLongitude;

    @Column(name="lease_latitude",length = 10, decimalLen = 6, note = "纬度")
    protected Double leaseLatitude;
    @Column(name = "lease_agent_id", note = "租借网点代理ID")
    protected Long leaseAgentId;

    @Column(name = "revert_device_sn", note = "归还充电柜设备序列号")
    protected String revertDeviceSn;

    @Column(name = "revert_device_type_id",note = "设备类型ID")
    protected String revertDeviceTypeId;

    @Column(name = "revert_device_type_name",note = "设备类型名称")
    protected String revertDeviceTypeName;

    @Column(name = "revert_slot_num", length = 4, note = "归还时插入的卡槽位置")
    protected Integer revertSlotNum;

    @Column(name = "revert_power", note = "归还时电量")
    protected Double revertPower;

    @Column(name = "revert_bind_note",note = "设备绑定信息")
    protected String revertBindNote;

    @Column(name = "revert_place_id", note = "网点ID")
    protected Long revertPlaceId;

    @Column(name = "revert_place_name", note = "网点名称")
    protected String revertPlaceName;

    @Column(name ="revert_province",note = "省")
    protected String revertProvince;

    @Column(name ="revert_city",note = "市")
    protected String revertCity;

    @Column(name = "revert_city_area",note = "城区")
    protected String revertCityArea;

    @Column(name="revert_address",length = 64, note = "网点地址")
    protected String revertAddress;

    @Column(name="revert_longitude",length = 10, decimalLen = 6, note = "经度")
    protected Double revertLongitude;

    @Column(name="revert_latitude",length = 10, decimalLen = 6, note = "纬度")
    protected Double revertLatitude;

    @Column(name = "revert_agent_id", note = "归还网点代理ID")
    protected Long revertAgentId;

    @Column(name = "battery_type",note = "电池类型")
    protected String batteryType;

    @Column(name = "battery_type_name",note = "电池类型名称")
    protected String batteryTypeName;

    @Column(name = "portable_battery_sn")
    protected String portableBatterySn;

    @Column(name = "member_id", notNull = true, note = "会员ID")
    protected Long memberId;

    @Column(name = "member_name", note = "会员名称")
    protected String memberName;

    @Column(name = "member_phone", length = 16,note = "会员手机号")
    protected String memberPhone;

    //费用Start

    @Column(name = "deposit_money", notNull = true,defVal = "0", note = "押金金额，单位：分")
    protected Integer depositMoney;

    @Column(name = "day_max_money", notNull = true,defVal = "0", note = "每天最大支付金额")
    protected Integer dayMaxMoney;

    @Column(name = "pay_interval_money", notNull = true,defVal = "0", note = "支付间隔的金额，单位：分")
    protected Integer payIntervalMoney;

    @Column(name = "free_times", notNull = true,defVal = "0", note = "免费时长，单位：分钟")
    protected Integer freeTimes;

    @Column(name = "use_duration", notNull = true,defVal = "0", note = "使用时长，单位：秒")
    protected Long useDuration;

    @Column(name = "start_date")
    protected Date startDate;

    @Column(name = "end_date")
    protected Date endDate;

    //费用End

    //支付属性Start
    @Column(name = "cost_mode", notNull = true,defVal = "1",note = "费用方式")
    protected Integer costMode;

    //订单金额大于等于支付金额，其误差来源于优惠
    @Column(name = "money", notNull = true,defVal = "0",note = "订单金额，单位：厘")
    protected Long money;

    @Column(name = "pay_money", notNull = true,defVal = "0",note = "支付金额，单位：分")
    protected Integer payMoney;

    @Column(name = "wallet_money", notNull = true,defVal = "0",note = "钱包金额，单位：厘")
    protected Long walletMoney;

    @Column(name = "coupon_id",note = "优惠券ID")
    protected String couponId;

    @Column(name = "coupon_title",length = 255,note = "优惠券标题")
    protected String couponTitle;

    @Column(name = "discount_money", notNull = true,defVal = "0",note = "优惠金额，单位：厘")
    protected Long discountMoney;

    @Column(name = "pay_type",notNull = true,defVal = "1",note = "支付类型")
    protected Integer payType;

    @Column(name = "pay_trade_no",length = 32,note = "支付订单")
    protected String payTradeNo;

    @Column(name = "pay_state",notNull = true, defVal = "1", note = "订单支付状态")
    protected Integer payState;

    @Column(name = "pay_date", note = "支付时间")
    protected Date payDate;

    //支付属性End

    @Column(notNull = true, defVal = "1", note = "订单状态")
    protected Integer state;

    @Column(name = "operate_state",notNull = true, defVal = "1", note = "操作状态，数据库锁字段")
    protected Integer operateState;

    @Column(name = "finish_date",note = "完成时间")
    protected Date finishDate;

    @Column(name = "cancel_date",note = "撤销时间")
    protected Date cancelDate;

    @Column(name = "update_date", autoUpdateTime = true, note = "修改时间")
    protected Date updateDate;

    @Column(name = "create_date",notNull = true)
    protected Date createDate;

    public String getTradeNo() {
        return tradeNo;
    }

    @Override
    public Long getPlaceId() {
        return this.leasePlaceId;
    }

    @Override
    public String getPlaceName() {
        return this.leasePlaceName;
    }

    @Override
    public String getPlaceAreaName() {
        return this.getLeaseAreaName();
    }

    public void setTradeNo(String tradeNo) {
        this.tradeNo = tradeNo;
    }

    public String getLeaseDeviceSn() {
        return leaseDeviceSn;
    }

    public void setLeaseDeviceSn(String leaseDeviceSn) {
        this.leaseDeviceSn = leaseDeviceSn;
    }

    public String getLeaseDeviceTypeId() {
        return leaseDeviceTypeId;
    }

    public void setLeaseDeviceTypeId(String leaseDeviceTypeId) {
        this.leaseDeviceTypeId = leaseDeviceTypeId;
    }

    public String getLeaseDeviceTypeName() {
        return leaseDeviceTypeName;
    }

    public void setLeaseDeviceTypeName(String leaseDeviceTypeName) {
        this.leaseDeviceTypeName = leaseDeviceTypeName;
    }

    public Long getLeaseIotId() {
        return leaseIotId;
    }

    public void setLeaseIotId(Long leaseIotId) {
        this.leaseIotId = leaseIotId;
    }

    public Integer getLeaseSlotNum() {
        return leaseSlotNum;
    }

    public void setLeaseSlotNum(Integer leaseSlotNum) {
        this.leaseSlotNum = leaseSlotNum;
    }

    public Double getLeasePower() {
        return leasePower;
    }

    public void setLeasePower(Double leasePower) {
        this.leasePower = leasePower;
    }

    public Integer getLeaseErrorState() {
        return leaseErrorState;
    }

    public void setLeaseErrorState(Integer leaseErrorState) {
        this.leaseErrorState = leaseErrorState;
    }

    public String getLeaseBindNote() {
        return leaseBindNote;
    }

    public void setLeaseBindNote(String leaseBindNote) {
        this.leaseBindNote = leaseBindNote;
    }

    public Long getLeasePlaceId() {
        return leasePlaceId;
    }

    public void setLeasePlaceId(Long leasePlaceId) {
        this.leasePlaceId = leasePlaceId;
    }

    public String getLeasePlaceName() {
        return leasePlaceName;
    }

    public void setLeasePlaceName(String leasePlaceName) {
        this.leasePlaceName = leasePlaceName;
    }

    public String getLeaseProvince() {
        return leaseProvince;
    }

    public void setLeaseProvince(String leaseProvince) {
        this.leaseProvince = leaseProvince;
    }

    public String getLeaseCity() {
        return leaseCity;
    }

    public void setLeaseCity(String leaseCity) {
        this.leaseCity = leaseCity;
    }

    public String getLeaseCityArea() {
        return leaseCityArea;
    }

    public void setLeaseCityArea(String leaseCityArea) {
        this.leaseCityArea = leaseCityArea;
    }

    public String getLeaseAddress() {
        return leaseAddress;
    }

    public void setLeaseAddress(String leaseAddress) {
        this.leaseAddress = leaseAddress;
    }

    public Double getLeaseLongitude() {
        return leaseLongitude;
    }

    public void setLeaseLongitude(Double leaseLongitude) {
        this.leaseLongitude = leaseLongitude;
    }

    public Double getLeaseLatitude() {
        return leaseLatitude;
    }

    public void setLeaseLatitude(Double leaseLatitude) {
        this.leaseLatitude = leaseLatitude;
    }

    public String getRevertDeviceSn() {
        return revertDeviceSn;
    }

    public void setRevertDeviceSn(String revertDeviceSn) {
        this.revertDeviceSn = revertDeviceSn;
    }

    public String getRevertDeviceTypeId() {
        return revertDeviceTypeId;
    }

    public void setRevertDeviceTypeId(String revertDeviceTypeId) {
        this.revertDeviceTypeId = revertDeviceTypeId;
    }

    public String getRevertDeviceTypeName() {
        return revertDeviceTypeName;
    }

    public void setRevertDeviceTypeName(String revertDeviceTypeName) {
        this.revertDeviceTypeName = revertDeviceTypeName;
    }

    public Integer getRevertSlotNum() {
        return revertSlotNum;
    }

    public void setRevertSlotNum(Integer revertSlotNum) {
        this.revertSlotNum = revertSlotNum;
    }

    public Double getRevertPower() {
        return revertPower;
    }

    public void setRevertPower(Double revertPower) {
        this.revertPower = revertPower;
    }

    public String getRevertBindNote() {
        return revertBindNote;
    }

    public void setRevertBindNote(String revertBindNote) {
        this.revertBindNote = revertBindNote;
    }

    public Long getRevertPlaceId() {
        return revertPlaceId;
    }

    public void setRevertPlaceId(Long revertPlaceId) {
        this.revertPlaceId = revertPlaceId;
    }

    public String getRevertPlaceName() {
        return revertPlaceName;
    }

    public void setRevertPlaceName(String revertPlaceName) {
        this.revertPlaceName = revertPlaceName;
    }

    public String getRevertProvince() {
        return revertProvince;
    }

    public void setRevertProvince(String revertProvince) {
        this.revertProvince = revertProvince;
    }

    public String getRevertCity() {
        return revertCity;
    }

    public void setRevertCity(String revertCity) {
        this.revertCity = revertCity;
    }

    public String getRevertCityArea() {
        return revertCityArea;
    }

    public void setRevertCityArea(String revertCityArea) {
        this.revertCityArea = revertCityArea;
    }

    public String getRevertAddress() {
        return revertAddress;
    }

    public void setRevertAddress(String revertAddress) {
        this.revertAddress = revertAddress;
    }

    public Double getRevertLongitude() {
        return revertLongitude;
    }

    public void setRevertLongitude(Double revertLongitude) {
        this.revertLongitude = revertLongitude;
    }

    public Double getRevertLatitude() {
        return revertLatitude;
    }

    public void setRevertLatitude(Double revertLatitude) {
        this.revertLatitude = revertLatitude;
    }

    public String getBatteryType() {
        return batteryType;
    }

    public void setBatteryType(String batteryType) {
        this.batteryType = batteryType;
    }

    public String getBatteryTypeName() {
        return batteryTypeName;
    }

    public void setBatteryTypeName(String batteryTypeName) {
        this.batteryTypeName = batteryTypeName;
    }

    public String getPortableBatterySn() {
        return portableBatterySn;
    }

    public void setPortableBatterySn(String portableBatterySn) {
        this.portableBatterySn = portableBatterySn;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public String getMemberName() {
        return memberName;
    }

    public void setMemberName(String memberName) {
        this.memberName = memberName;
    }

    public String getMemberPhone() {
        return memberPhone;
    }

    public void setMemberPhone(String memberPhone) {
        this.memberPhone = memberPhone;
    }

    public Long getLeaseAgentId() {
        return leaseAgentId;
    }

    public void setLeaseAgentId(Long leaseAgentId) {
        this.leaseAgentId = leaseAgentId;
    }

    public Long getRevertAgentId() {
        return revertAgentId;
    }

    public void setRevertAgentId(Long revertAgentId) {
        this.revertAgentId = revertAgentId;
    }

    public Integer getDepositMoney() {
        return depositMoney;
    }

    public void setDepositMoney(Integer depositMoney) {
        this.depositMoney = depositMoney;
    }

    public Integer getDayMaxMoney() {
        return dayMaxMoney;
    }

    public void setDayMaxMoney(Integer dayMaxMoney) {
        this.dayMaxMoney = dayMaxMoney;
    }

    public Integer getPayIntervalMoney() {
        return payIntervalMoney;
    }

    public void setPayIntervalMoney(Integer payIntervalMoney) {
        this.payIntervalMoney = payIntervalMoney;
    }

    public Integer getFreeTimes() {
        return freeTimes;
    }

    public void setFreeTimes(Integer freeTimes) {
        this.freeTimes = freeTimes;
    }

    public Long getUseDuration() {
        return useDuration;
    }

    public void setUseDuration(Long useDuration) {
        this.useDuration = useDuration;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Integer getCostMode() {
        return costMode;
    }

    public void setCostMode(Integer costMode) {
        this.costMode = costMode;
    }

    public Long getMoney() {
        return money;
    }

    public void setMoney(Long money) {
        this.money = money;
    }

    public Long getDiscountMoney() {
        return discountMoney;
    }

    public void setDiscountMoney(Long discountMoney) {
        this.discountMoney = discountMoney;
    }

    public Integer getPayMoney() {
        return payMoney;
    }

    public void setPayMoney(Integer payMoney) {
        this.payMoney = payMoney;
    }

    public Long getWalletMoney() {
        return walletMoney;
    }

    public void setWalletMoney(Long walletMoney) {
        this.walletMoney = walletMoney;
    }

    public String getCouponId() {
        return couponId;
    }

    public void setCouponId(String couponId) {
        this.couponId = couponId;
    }

    public String getCouponTitle() {
        return couponTitle;
    }

    public void setCouponTitle(String couponTitle) {
        this.couponTitle = couponTitle;
    }

    public Integer getPayType() {
        return payType;
    }

    public void setPayType(Integer payType) {
        this.payType = payType;
    }

    public String getPayTradeNo() {
        return payTradeNo;
    }

    public void setPayTradeNo(String payTradeNo) {
        this.payTradeNo = payTradeNo;
    }

    public Date getPayDate() {
        return payDate;
    }

    public void setPayDate(Date payDate) {
        this.payDate = payDate;
    }

    public Integer getPayState() {
        return payState;
    }

    public void setPayState(Integer payState) {
        this.payState = payState;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Integer getOperateState() {
        return operateState;
    }

    public Date getFinishDate() {
        return finishDate;
    }

    public void setFinishDate(Date finishDate) {
        this.finishDate = finishDate;
    }

    public Date getCancelDate() {
        return cancelDate;
    }

    public void setCancelDate(Date cancelDate) {
        this.cancelDate = cancelDate;
    }

    public void setOperateState(Integer operateState) {
        this.operateState = operateState;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getPayTypeName(){
        return EPayType.note(this.payType);
    }

    public String getCostModeName(){
        return EBXSCNCostMode.note(this.costMode);
    }

    public String getPayMoneyStr(){
        return NumberTools.getMoneyStr(this.payMoney);
    }

    public String getMoneyStr(){
        return NumberTools.getMoneyLiStr(this.money);
    }

    public String getDiscountMoneyStr(){
        return NumberTools.getMoneyLiStr(this.discountMoney);
    }

    public String getDepositMoneyStr(){
        return NumberTools.getMoneyStr(this.depositMoney);
    }

    public String getWalletMoneyStr(){
        return NumberTools.getMoneyLiStr(this.walletMoney);
    }

    public String getDayMaxMoneyStr(){
        return NumberTools.getMoneyStr(this.dayMaxMoney);
    }

    public String getPayIntervalMoneyStr(){
        return NumberTools.getMoneyStr(this.payIntervalMoney);
    }

    public String getUseDurationStr(){
        if(this.useDuration == null || this.useDuration == 0){
            if(this.startDate != null){
                this.useDuration = DateTools.differenceSecond(this.startDate,new Date());
            }
        }
        if(this.useDuration != null) {
            if (this.useDuration > 3600) {
                long hour = this.useDuration / 3600;
                long minute = (this.useDuration % 3600) / 60;
                if (minute > 0) {
                    return hour + "小时" + minute + "分钟";
                } else {
                    return hour + "小时";
                }
            } else if (this.useDuration > 60) {
                long minute = this.useDuration / 60;
                return minute + "分钟";
            }
        }
        return "1分钟内";
    }

    public String getStateName(){
        return BXSCNOrderEnum.State.note(this.state);
    }

    public String getPayStateName(){
        return BXSCNOrderEnum.PayState.note(this.payState);
    }

    public String getLeaseAreaName(){
        return this.leaseProvince + "-" + this.leaseCity + "-" + this.leaseCityArea;
    }

    public String getRevertAreaName(){
        if(StringTools.isNotBlank(this.revertProvince)) {
            return this.revertProvince + "-" + this.revertCity + "-" + this.revertCityArea;
        }
        return "--";
    }

    public String getLeaseFullAddress() {
        String temp = this.leaseProvince + "-" + this.leaseCity + "-" + this.leaseCityArea;
        if (StringTools.isNotBlank(this.leaseAddress)) {
            return temp + this.leaseAddress;
        } else {
            return temp;
        }
    }

    public String getRevertFullAddress() {
        String temp = this.revertProvince + "-" + this.revertCity + "-" + this.revertCityArea;
        if (StringTools.isNotBlank(this.revertAddress)) {
            return temp + this.revertAddress;
        } else {
            return temp;
        }
    }

    public Long getIncomeMoney(){
        if(this.walletMoney == null){
            this.walletMoney = 0L;
        }
        if(this.payMoney == null){
            this.payMoney = 0;
        }
        return this.walletMoney + NumberTools.changeMoneyLi(NumberTools.changeMoney(this.payMoney));
    }

    public String getLeaseErrorStateName(){
        return BXSCNOrderEnum.LeaseErrorState.note(this.leaseErrorState);
    }
}
